/**
 * LeetCode206：反转链表
 * 反转一个单链表
 */

/**
 * 定义链表节点
 */
function ListNode(val){
    this.val = val;
    this.next = next;
}

/**
 *
 * @param {ListNode}head
 * @returns {ListNode}
 */
var reverseList = function (head){
    let p1 = head;
    let p2 = null;
    while (p1){
        const tmp = p1.next;
        p1.next = p2;
        p2 = p1;
        p1 = tmp;
    };
    return p2;
};

//时间复杂度：O(n)
//空间复杂度：O(1)